package rauguelu.programaEventos;

import java.util.ArrayList;

import rauguelu.programaEventos.feedTweet.Tweet;
import rauguelu.programaEventos.feedTweet.ViewHolder;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<Tweet>  data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    
    public LazyAdapter(Activity a, ArrayList<Tweet> tweet) {
        activity = a;
        data=tweet;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public void add(Tweet tweet)
    {
    	data.add(tweet);
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        ViewHolder holder;
        //add the footer before adding the adapter, else the footer will not load!
        
        if(convertView==null)
            vi = inflater.inflate(R.layout.listitem_tweet, null);
        holder = new ViewHolder();
		 
        TextView username = (TextView)vi.findViewById(R.id.username);
        TextView message = (TextView)vi.findViewById(R.id.message);
        ImageView image=(ImageView)vi.findViewById(R.id.avatar);
        
//        Typeface font2 = Typeface.createFromAsset(getAssets(), "VSVAB.TTF");
//		username.setTypeface(font2); 
        
        Tweet tweet = data.get(position);
        if (tweet != null) {
        
            username.setText(data.get(position).username);
            message.setText(data.get(position).message);
            imageLoader.DisplayImage(data.get(position).image_url, activity, image);
            
            //image.setImageBitmap(getBitmap(tweets.get(position).image_url));
        }
        
        //imageLoader.DisplayImage((data.get(position).image_url, activity, image);
        return vi;
    }
}
